<template>
  <div class="featured-posts">
    <h3 class="section-title">推荐文章</h3>
    <div class="post-list">
      <router-link 
        v-for="article in latestArticles" 
        :key="article.id"
        :to="{ name: 'article', params: { id: article.id }}"
        class="post-item"
      >
        <div class="post-content">
          <h4 class="post-title">{{ article.title }}</h4>
          <div class="post-meta">
            <div class="author-info">
              <img :src="article.author_avatar" :alt="article.author_name" class="author-avatar">
              <span class="author-name">{{ article.author_name }}</span>
            </div>
            <div class="stats">
              <span class="stat-item">
                <i class="fas fa-comment"></i>
                {{ article.comment_count }}
              </span>
              <span class="stat-item">
                <i class="fas fa-heart"></i>
                {{ article.like_count }}
              </span>
            </div>
          </div>
        </div>
      </router-link>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { useArticleStore } from '../stores/articleStore'

const articleStore = useArticleStore()

// 获取最新的5篇文章
const latestArticles = computed(() => articleStore.getLatestArticles(5))
</script>

<style scoped>
.featured-posts {
  background: white;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.section-title {
  font-size: 18px;
  color: var(--text-color);
  margin-bottom: 16px;
  padding-left: 8px;
  font-weight: 500;
}

.post-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.post-item {
  display: block;
  padding: 12px;
  text-decoration: none;
  color: inherit;
  border-radius: 6px;
  transition: all 0.2s;
}

.post-item:hover {
  background-color: rgba(0, 0, 0, 0.02);
}

.post-title {
  font-size: 15px;
  margin: 0 0 8px 0;
  color: var(--text-color);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

.post-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.author-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.author-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
}

.author-name {
  font-size: 13px;
  color: var(--text-light);
}

.stats {
  display: flex;
  gap: 12px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-lighter);
  font-size: 12px;
}

.stat-item i {
  font-size: 12px;
}

.post-item:hover .post-title {
  color: var(--primary-color);
}
</style> 